<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Menu_ctrl extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->library('auth');
		$this->load->library('layouts');
		$this->load->model('menu_mdl');
	}

	public function index()
	{
		if($this->auth->is_logged_in() == false)
		{
			redirect('login/login');
		}
		else
		{
			$data['nama_user']=$this->session->userdata('SESS_NAMA_LENGKAP');
			$data['page_title']='Kontraktor';
			$data['view_data']=json_encode($this->menu_mdl->getListMenu());
			$this->load->view('module/menu_view',$data);
		}
	} 
	
	public function show_page()
	{
		$menu_id=$this->input->post('menu_id');
		switch ($menu_id)
		{
			case "2":
				echo "Text: Application Module Lis";
				break;
			case "3":
				//echo " Menu Structure";
				$data['nama_user']=$this->session->userdata('SESS_NAMA_LENGKAP');
				$data['page_title']='Kontraktor';
				$data['view_data']=json_encode($this->menu_mdl->getListMenu());
				$this->load->view('module/menu_view',$data);
				break;
			case "5":
				echo "User Group";
								
				break;
			case "6":
				echo "User Account";
				
				break;
			case "8":
				echo "Table List";
				
				break;
			case "9":
				echo "Log Managemen";
				
				break;
			case "10":
				echo "Backup Data";
				
				break;
			case "11":
				echo "Optimizing Database";
				
				break;
			case "13":
				//echo "Kontraktor";
				$this->load->model('kontraktor_mdl');
				$data['nama_user']=$this->session->userdata('SESS_NAMA_LENGKAP');
				$data['page_title']='Kontraktor';
				$data['view_data']=json_encode($this->kontraktor_mdl->getListKontraktor());
				$this->load->view('module/kontraktor_view',$data);
				break;
			case "14":
				//echo "Bank";
				$this->load->model('bank_mdl');
				$data['nama_user']=$this->session->userdata('SESS_NAMA_LENGKAP');
				$data['page_title']='Bank KPR';
				$data['view_data']=json_encode($this->bank_mdl->getListBank());
				$this->load->view('module/bank_view',$data);
				break;
			case "15":
				echo "Sales";
				
				break;
			case "16":
				echo "Customer";
				
				break;
			case "18":
				echo "Dokumen Template";
				
				break;
			case "19":
				echo "Dokumen Customer ";
				
				break;
			case "21":
				echo "Spesifikasi Bangunan";
				
				break;
			case "22":
				echo "Spesifikasi Class";
				
				break;
			case "23":
				echo "Class Properti";
				
				break;
			case "25":
				echo "New parameter";
				
				break;
			case "26":
				echo "Penyusunan Harga";
				
				break;
			case "27":
				echo "Type Pembayaran";
				
				break;
			case "29":
				echo "Pesanan Properti";
				
				break;
			case "30":
				echo "Lokasi Properti";
				
				break;
			case "31":
				//echo "Properti";
				$data['layout_title']='Property Management';
				$this->load->model('property_mdl');
				$data['view_data']=json_encode($this->property_mdl->getListProperty());
				$this->load->view('module/property_view',$data);
				
				break;
			case "32":
				echo "Transaksi penjualan";
				
				break;
			default:
				echo "Welcome....!!";
		}	
	}
	
	function Save(){
		if( !empty( $_POST ) ) {
			if ($this->input->post('ajax')){
				$action = $this->input->post('action');
				$id= trim($this->input->post('idmenu'));
				$text= $this->input->post('text');
				$page_name= $this->input->post('page_name');
				$parentid= $this->input->post('parentid');
				$subMenuWidth= $this->input->post('subMenuWidth');
				$classname= $this->input->post('classname');
				$functionname= $this->input->post('functionname');
				$visible= $this->input->post('visible');
				$data = array(
						'idmenu'=>$id,
						'text'=>$text,
						'page_name'=>$page_name,
						'parentid'=>$parentid,
						'subMenuWidth'=>$subMenuWidth,
						'classname'=>$classname,
						'functionname'=>$functionname,
						'visible'=>$visible
				);
				if ($action=="A"){
					$this->menu_mdl->SaveAdd($data);
				} 
			}
		}	
	}
	
	function Edit(){
		if( !empty( $_POST ) ) {
			if ($this->input->post('ajax')){
				$action = $this->input->post('action');
				$id= trim($this->input->post('idmenu'));
				$text= $this->input->post('text');
				$page_name= $this->input->post('page_name');
				$parentid= $this->input->post('parentid');
				$subMenuWidth= $this->input->post('subMenuWidth');
				$classname= $this->input->post('classname');
				$functionname= $this->input->post('functionname');
				$visible= $this->input->post('visible');
				$data = array(
						//'idmenu'=>$id,
						'text'=>$text,
						'page_name'=>$page_name,
						'parentid'=>$parentid,
						'subMenuWidth'=>$subMenuWidth,
						'classname'=>$classname,
						'functionname'=>$functionname,
						'visible'=>$visible
				);
				if ($action=="E"){
					$this->menu_mdl->SaveEdit($data);
				}
			}
		}	
	}

	function Delete(){
		if( !empty( $_POST ) ) {
			$id=trim($this->input->post('idmenu'));
			$this->menu_mdl->DeleteMenu($id);
		}		
	}
	
	function Refresh(){
		$data['view_data']=json_encode($this->menu_mdl->getListMenu());
		$this->load->view('module/menu_view',$data);
	}
		
	
	
}
